# -*- coding: utf-8 -*-
import re,os
import urlparse
import post

def upload(article):
    params = (#("dxid",article.send_data.dxid),
              #("id",article.send_data.id),
              ("mail.content",article.send_data.mailcontent),
              ("mail.oldcon", article.send_data.mailoldcon),
              ("mail.title", article.send_data.mailtitle),
              ("mail.user", article.send_data.mailuser),
              #("passtype", article.send_data.passtype),
              #("repaytype", article.send_data.repaytype),
              #("state", article.send_data.state),
              #("type", article.send_data.type),
              
              )
    if not os.path.exists(article.send_data.uploadfile):
        print article.send_data.uploadfile
        exit(1)
    #d = open(article.send_data.uploadfile,'rb')
    d = open('pdf\\senlan.pdf','rb')
    print article.send_data.uploadfile
    #params2 = (("upload",article.send_data.uploadfile,d.read()),)
    params2 = (("upload",'senlan.pdf',d.read()),)
    urlparts = urlparse.urlsplit("http://www.firstdrs.com/admin/first/sendmail.do")
    r = post.post_multipart(urlparts[1],urlparts[2], params,params2)
    result = re.findall("alert\('(.*?)'\)",r)[0]
    print article.title + result.decode('UTF-8').encode('gbk')
    #f = open('rrr.html','wb')
    #f.write(r)
    #f.close()
